package com.atguigu.srpingcloud.controller;

import com.atguigu.srpingcloud.service.HystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.ConditionalOnEnabledResourceChain;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author yangjin
 * @Description
 * @Date 2021/6/28/21:31
 **/
@RestController
@Slf4j
public class HystrixController {

    @Resource
    private HystrixService hystrixService;

    @Value("${server.port}")
    private String serverPrt;

    /**
     * 模拟响应正常
     * @param id
     * @return
     */
    @GetMapping("/privoder/hystrix/callSuccess/{id}")
    public String getCallSuccess(@PathVariable("id") Integer id){
        return hystrixService.paymentInfo_call_ok(id);
    }

    /**
     * 模拟响应失败
     * @param id
     * @return
     */
    @GetMapping("/privoder/hystrix/callFail/{id}/{sleepSecond}")
    public String getCallFail(@PathVariable("id") Integer id,@PathVariable("sleepSecond") Integer sleepSecond){
        return hystrixService.paymentInfo_call_fail(id,sleepSecond);
    }


    @GetMapping("/payment/circuit/{id}")
    public String paymentCircuitBreaker(@PathVariable("id") Integer id)
    {
        String result = hystrixService.paymentCircuitBreaker(id);
        log.info("****result: "+result);
        return result;
    }

}
